package luj.tool.jnproxyan.proxy.util.data;

import luj.bean.api.BeanContext;
import luj.bean.api.bean.Bean;
import luj.data.api.Data;
import luj.data.api.DataContext;
import luj.data.api.use.UseGroup;
import luj.tool.jnproxyan.proxy.database.DatabaseState;
import luj.tool.jnproxyan.proxy.util.data.wrap.DataResultWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicLong;

@Component
public class DataBeanCreator {

  @Deprecated
  public <T> T create(Class<T> type) {
    Bean<T> bean = _lujbean.createBean(type);

//    Data data = _lujdata.createData(bean.getBeanType());
//    bean.getFieldMap().putAll(data.toMap());

    return bean.getValueInstance();
  }

  public <T> T createV2(Class<T> type, UseGroup using, DatabaseState dbState) {
    Data data = _dataMaker.inject(type, dbState).create();

    return _dataWrapper.wrap(data, type, using, true);
  }

  @Autowired
  DataNewCreator _dataMaker;

  @Autowired
  DataResultWrapper _dataWrapper;

  @Deprecated
  @Autowired
  BeanContext _lujbean;
}
